home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 …ember: Reference Library / Dev.CD Dec 98 RL1.toast / Technical Documentation / develop / develop Issue 23 / develop Issue 23 code / Multipane Dialogs Code.sea / Multipane Dialogs Code / PP / CPrefDialog.cp / CPrefDialog.cp
Encoding:
Text File  |  1995-10-17  |  2.7 KB  |  128 lines  |  [TEXT/MMCC]

  1. #include "CPrefDialog.h"
  2. #include "MPDialogs.h"
  3.  
  4. StPrefDialog::StPrefDialog(LCommander *inSuper, ResIDT inMenu, ResIDT inDialogID, Handle &ioHandle)
  5.     : LCommander(inSuper)
  6. {
  7.     HiliteMenu(inMenu);
  8.     mPrefsDialog =
  9.         OpenMPDialog(inDialogID, nil, nil, nil, nil, &ioHandle);
  10.     
  11.     mMessage = msg_Nothing;
  12.     mSleepTime = 6;
  13.     
  14.     SwitchTarget(this);
  15. }
  16.  
  17. StPrefDialog::~StPrefDialog()
  18. {
  19.     if (mPrefsDialog) CloseMPDialog(&mPrefsDialog);
  20.     LView::OutOfFocus(nil);
  21.     HiliteMenu(0);
  22. }
  23.  
  24. MessageT
  25. StPrefDialog::DoDialog()
  26. {
  27.     EventRecord macEvent;
  28.     short result;
  29.  
  30.     SetUpdateCommandStatus(true);
  31.     UpdateMenus();
  32.  
  33.     if (IsOnDuty()) {
  34.         ::OSEventAvail(0, &macEvent);
  35.         AdjustCursor(macEvent);
  36.     }
  37.  
  38.     while (mPrefsDialog) {
  39.         Boolean gotEvent = ::WaitNextEvent(everyEvent, &macEvent, mSleepTime, mMouseRgnH);
  40.         mMessage = msg_Nothing;
  41.     
  42.         if (DoMPDialogEvent(&mPrefsDialog, &macEvent, &result)) {
  43.             if (!mPrefsDialog) switch (result) {
  44.                 case kNotClosed:
  45.                 case kCancelClosed:
  46.                     return cmd_Nothing;
  47.                 case kOKClosed:
  48.                     return cmd_Save;
  49.             }
  50.         }
  51.  
  52.         switch (macEvent.what) {
  53.             case autoKey:
  54.             case keyUp:
  55.             case keyDown:
  56.                 continue;
  57.         }
  58.  
  59.         if (LEventDispatcher::ExecuteAttachments(msg_Event, &macEvent)) {
  60.             if (gotEvent) {
  61.                 DispatchEvent(macEvent);
  62.             } else {
  63.                 UseIdleTime(macEvent);
  64.             }
  65.         }
  66.     
  67.         LPeriodical::DevoteTimeToRepeaters(macEvent);
  68.     }
  69.     
  70.     if (IsOnDuty() && GetUpdateCommandStatus()) {
  71.         UpdateMenus();
  72.     }
  73.  
  74.     return mMessage;
  75. }
  76.  
  77. void
  78. StPrefDialog::FindCommandStatus(
  79.     CommandT    inCommand,
  80.     Boolean        &outEnabled,
  81.     Boolean&    /* outUsesMark */,
  82.     Char16&        /* outMark */,
  83.     Str255        /* outName */)
  84. {
  85.         // Don't enable any commands except cmd_About, which will keep
  86.         // the Apple menu enabled. This function purposely does not
  87.         // call the inherited FindCommandStatus, thereby suppressing
  88.         // commands that are handled by SuperCommanders. Only those
  89.         // commands enabled by SubCommanders will be active.
  90.     
  91.     outEnabled = false;
  92.     if (inCommand == cmd_About) {
  93.         outEnabled = true;
  94.     }
  95. }
  96.  
  97. void
  98. StPrefDialog::EventMouseDown(const EventRecord &inMacEvent)
  99. {
  100.     WindowPtr    macWindowP;
  101.     Int16        thePart = ::FindWindow(inMacEvent.where, &macWindowP);
  102.     
  103.     switch (thePart) {
  104.  
  105.         case inContent:
  106.             LCommander::SetUpdateCommandStatus(true);
  107.             // Fall Thru
  108.         case inDrag:
  109.         case inGrow:
  110.         case inGoAway:
  111.         case inZoomIn:
  112.         case inZoomOut:
  113.             if (macWindowP != ::FrontWindow() && mPrefsDialog) {
  114.                  // Front Window is Modal
  115.                  if ( (thePart != inDrag) || !(inMacEvent.modifiers & cmdKey) ) {
  116.                                         // Dispatch click to Window object
  117.                     LWindow    *theWindow = LWindow::FetchWindowObject(macWindowP);
  118.                     if (theWindow != nil) {
  119.                         theWindow->HandleClick(inMacEvent, click_OutsideModal);
  120.                         return;
  121.                     }
  122.                 }
  123.             }
  124.             break;
  125.     }
  126.     LEventDispatcher::EventMouseDown(inMacEvent);
  127. }
  128.